<template>
  <a-card class="j-inner-table-wrapper" :bordered="false">

    <!-- 操作按钮区域 begin -->
    <div class="table-operator">
     
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-button>
          <span>批量操作</span>
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
       <span>已选择</span>
          <a style="font-weight: 600;padding: 0 4px;">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
    </div>
    <!-- 操作按钮区域 end -->

    <!-- table区域 begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{x:true}"
        :loading="loading"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :expandedRowKeys="expandedRowKeys"
        :rowSelection="{selectedRowKeys, onChange: onSelectChange}"
        @expand="handleExpand"       
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="ellipsisText" slot-scope="text">
          <j-ellipsis :value="text" :length="textMaxLength"></j-ellipsis>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <div style="font-size: 12px;font-style: italic;">
            <span v-if="!text">无图片</span>
            <img v-else :src="getImgView(text)" alt="" style="max-width:80px;height:25px;"/>
          </div>
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            ghost
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)"
          >
            <span>下载</span>
          </a-button>
        </template>

      </a-table>
    </div>
    <!-- table区域 end -->

  </a-card>
</template>

<script>

  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import { deleteAction, getAction,downFile,getFileAccessHttpUrl } from '@/api/manage'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import '@/assets/less/TableExpand.less'

  export default {
    name: 'ChgArrearsList',
    components: {
      JEllipsis,  
      JDictSelectTag,
    },
    data() {
      return {
        description: '欠费记录列表核销选择管理页面',
        textMaxLength:5,
        accCode:'',
        username:'',
        // 表头
        columns: [
          {
            title: '#',
            key: 'rowIndex',
            width: 60,
            align: 'center',
            customRender: (t, r, index) => parseInt(index) + 1
          },
          {
            title: '用户号',
            align: 'center',
            dataIndex: 'cusId'
          },
          {
            title: '用户名',
            align: 'center',
            dataIndex: 'cusName',
            scopedSlots: {customRender: "ellipsisText"}
          },         
          {
            title: '月份',
            align: 'center',
            dataIndex: 'readMonth',
          },
          {
            title: '起度',
            align: 'center',
            dataIndex: 'beginScale',
          },
          {
            title: '止度',
            align: 'center',
            dataIndex: 'endScale',
          },
          {
            title: '计费水量',
            align: 'center',
            dataIndex: 'measureAmount',
          },
          {
            title: '水费',
            align: 'center',
            dataIndex: 'totalMoney',
          },
          {
            title:'污水费',
            align:"center",
            dataIndex: 'wuMoney'
          },
          {
            title:'垃圾费',
            align:"center",
            dataIndex: 'ljMoney'
          },
          {
            title: '杂项费',
            align: 'center',
            dataIndex: 'alienMoney',
          },
          {
            title: '实计金额',
            align: 'center',
            dataIndex: 'money',
          },
          {
            title: '违约金',
            align: 'center',
            dataIndex: 'penalty',
          },
          {
            title: '欠费金额',
            align: 'center',
            dataIndex: 'arrearMoney',
          },        
        ],
        // 字典选项
        dictOptions: {},
        // 展开的行test
        expandedRowKeys: [],
         /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
        queryParam: {},
        /* 数据源 */
        dataSource:[],
        /* 分页参数 */
        ipagination:{
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '50', '100', '300'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        /* 排序参数 */
        isorter:{
          column: 'createTime',
          order: 'desc',
        },
        /* 筛选参数 */
        filters: {},
        /* table加载状态 */
        loading:false,
        /* table选中keys*/
        selectedRowKeys: [],
        /* table选中records*/
        selectionRows: [],
        /* 查询折叠 */
        toggleSearchStatus:false,
        /* 高级查询条件生效状态 */
        superQueryFlag:false,
        /* 高级查询条件 */
        superQueryParams: '',
        /** 高级查询拼接方式 */
        superQueryMatchType: 'and', 
        url: {
          list: '/chg/chgArrears/list',       
        },
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
      this.username = this.userInfo.username;
    },
    computed: {
      importExcelUrl() {
        return window._CONFIG['domianURL'] + this.url.importExcelUrl
      },
      userInfo() {
        return this.$store.getters.userInfo
      } 
    },
    methods: {
      initDictConfig() {
      },

      handleExpand(expanded, record) {
        this.expandedRowKeys = []
        if (expanded === true) {
          this.expandedRowKeys.push(record.id)
        }
      },
      edit (record) {      
        this.queryParam.cusId = record.accCode;
        this.visible = true;
        if(this.queryParam.cusId){
          this.loadData();
        }
      },
      close() {
        this.visible = false
        this.$emit('close')
      },      
      getSelectKeys(){
        this.visible = false
        return this.selectedRowKeys;
      },
      loadData() {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
    
        var params = this.queryParam;//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
      onSelectChange(selectedRowKeys, selectionRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectionRows = selectionRows;
      },
      onClearSelected() {
        this.selectedRowKeys = [];
        this.selectionRows = [];
      },
      getSuperFieldList(){
        let fieldList=[];
        // fieldList.push({type:'string',value:'cusId',text:'用户号',dictCode:'mws_t_arc_customers,code,id'})
        // fieldList.push({type:'string',value:'cusName',text:'用户名',dictCode:''})
        fieldList.push({type:'string',value:'natureId',text:'用水性质',dictCode:'mws_t_base_natures,name,id'})
        fieldList.push({type:'string',value:'readMonth',text:'月份',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'beginScale',text:'起度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'endScale',text:'止度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'readAmount',text:'抄见水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'replaceMeterScale',text:'换表读数',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'replaceAmount',text:'换表水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'measureAmount',text:'计量水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'ajustedAmount',text:'减免水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'amount',text:'计费水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'totalMoney',text:'合计金额(仅水费)',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'vatMoney',text:'增值税金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'discountMoney',text:'优惠金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'alienMoney',text:'杂项金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'money',text:'折后金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'penalty',text:'违约金',dictCode:''})
        fieldList.push({type:'int',value:'penaltyDay',text:'违约天数',dictCode:''})
        fieldList.push({type:'string',value:'readerId',text:'抄表员',dictCode:''})
        fieldList.push({type:'string',value:'bookId',text:'抄表本号',dictCode:'mws_t_mr_books,name,id'})
        fieldList.push({type:'string',value:'readTime',text:'抄表日期',dictCode:''})
        fieldList.push({type:'string',value:'waterUsedType',text:'水表状态',dictCode:'water_used_type'})
        fieldList.push({type:'BigDecimal',value:'recivedMoney',text:'已收金额',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'arrearMoney',text:'欠费金额包括违约金',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'recivedAmount',text:'已收水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'arrearAmount',text:'欠费水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lockedAmount',text:'锁定水量',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'lockedMoney',text:'锁定金额',dictCode:''})
        fieldList.push({type:'string',value:'operatedTime',text:'操作日期',dictCode:''})
        fieldList.push({type:'int',value:'remindNum',text:'短信催缴次数',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style lang="less" scoped>
  @import '~@assets/less/common.less';
</style>

